<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <!--<el-form-item label="用户id" prop="mobileUserId">-->
        <!--<el-input-->
          <!--v-model="queryParams.mobileUserId"-->
          <!--placeholder="请输入用户id"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="商品名称" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="标题" prop="title">-->
        <!--<el-input-->
          <!--v-model="queryParams.title"-->
          <!--placeholder="请输入标题"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="经度" prop="lat">-->
        <!--<el-input-->
          <!--v-model="queryParams.lat"-->
          <!--placeholder="请输入经度"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="纬度" prop="lng">-->
        <!--<el-input-->
          <!--v-model="queryParams.lng"-->
          <!--placeholder="请输入纬度"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="详情" prop="detail">
        <el-input
          v-model="queryParams.detail"
          placeholder="请输入详情"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格" prop="money">
        <el-input
          v-model="queryParams.money"
          placeholder="请输入价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="瞬间类型" prop="momentType">-->
        <!--<el-select v-model="queryParams.momentType" placeholder="选择瞬间类型" clearable size="small" prop="momentType">-->
          <!--<el-option-->
            <!--v-for="dict in statusOptions"-->
            <!--:key="dict.dictValue"-->
            <!--:label="dict.dictLabel"-->
            <!--:value="dict.dictValue"-->
          <!--/>-->
        <!--</el-select>-->
        <!--&lt;!&ndash;<el-select v-model="queryParams.momentType" placeholder="" clearable size="small">&ndash;&gt;-->
          <!--&lt;!&ndash;<el-option v-for="item in [{value: '0', label: '图片' }, {value: '1', label: '视频' }]"  :key="item.value" :label="item.label" :value="item.value" />&ndash;&gt;-->
        <!--&lt;!&ndash;</el-select>&ndash;&gt;-->
      <!--</el-form-item>-->
      <!--<el-form-item label="视频截图图片地址" prop="videoUrl">-->
        <!--<el-input-->
          <!--v-model="queryParams.videoUrl"-->
          <!--placeholder="请输入视频截图图片地址"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="地址名称" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="审核失败原因" prop="reason">-->
        <!--<el-input-->
          <!--v-model="queryParams.reason"-->
          <!--placeholder="请输入审核失败原因"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="是否审核" prop="examineStatus">-->
        <!--<el-select v-model="queryParams.examineStatus" placeholder="请选择是否审核" clearable size="small">-->
          <!--<el-option label="请选择字典生成" value="" />-->
        <!--</el-select>-->
      <!--</el-form-item>-->
      <el-form-item label="审核状态">
        <el-select v-model="queryParams.examineStatus" placeholder="选择审核状态" clearable size="small" prop="examineStatus">
          <el-option
            v-for="dict in Options"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上架状态">
        <el-select v-model="queryParams.itemStatus" placeholder="选择上架状态" clearable size="small" prop="itemStatus">
          <el-option
            v-for="dict in itemOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="浏览量" prop="pageviews">-->
        <!--<el-input-->
          <!--v-model="queryParams.pageviews"-->
          <!--placeholder="请输入浏览量"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="点赞数" prop="praises">-->
        <!--<el-input-->
          <!--v-model="queryParams.praises"-->
          <!--placeholder="请输入点赞数"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="评论数" prop="comments">-->
        <!--<el-input-->
          <!--v-model="queryParams.comments"-->
          <!--placeholder="请输入评论数"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!--<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
          <!--v-hasPermi="['system:goods:add']"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="success"-->
          <!--icon="el-icon-edit"-->
          <!--size="mini"-->
          <!--:disabled="single"-->
          <!--@click="handleUpdate"-->
          <!--v-hasPermi="['system:goods:edit']"-->
        <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="danger"-->
          <!--icon="el-icon-delete"-->
          <!--size="mini"-->
          <!--:disabled="multiple"-->
          <!--@click="handleDelete"-->
          <!--v-hasPermi="['system:goods:remove']"-->
        <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="warning"-->
          <!--icon="el-icon-download"-->
          <!--size="mini"-->
          <!--@click="handleExport"-->
          <!--v-hasPermi="['system:goods:export']"-->
        <!--&gt;导出</el-button>-->
      <!--</el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="用户id" align="center" prop="goodsId" />-->
      <!--<el-table-column label="用户id" align="center" prop="mobileUserId" />-->
      <el-table-column label="商品名称" align="center" prop="goodsName" />
      <el-table-column label="标题" align="center" prop="title" />
      <!--<el-table-column label="经度" align="center" prop="lat" />-->
      <!--<el-table-column label="纬度" align="center" prop="lng" />-->
      <el-table-column label="详情" align="center" prop="detail" />
      <el-table-column label="价格" align="center" prop="money" />
      <!--<el-table-column label="瞬间类型" align="center" prop="momentType" :formatter="Format"/>-->
      <el-table-column label="视频/图片" align="center" prop="videoUrl" />
      <el-table-column label="地址名称" align="center" prop="address" />
      <el-table-column label="审核失败原因" align="center" prop="reason" min-width="60" :show-overflow-tooltip="true"/>
      <el-table-column label="审核状态" align="center" prop="examineStatus":formatter="statusFormat" />
      <el-table-column label="上架状态" align="center" prop="itemStatus":formatter="statusFormat1" />
      <!--<el-table-column label="是否审核" align="center" prop="examineStatus" />-->
      <el-table-column label="浏览量" align="center" prop="pageviews" />
      <el-table-column label="点赞数" align="center" prop="praises">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handpraises(scope.row)">{{scope.row.praises}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="评论数" align="center" prop="comments">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handcomments(scope.row)">{{scope.row.comments}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if = "scope.row.examineStatus ==0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:goods:edit']"
          >审核</el-button>
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-delete"-->
            <!--@click="handleDelete(scope.row)"-->
            <!--v-hasPermi="['system:goods:remove']"-->
          <!--&gt;删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改二手物品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <!--<el-form-item label="用户id" prop="mobileUserId">-->
          <!--<el-input v-model="form.mobileUserId" placeholder="请输入用户id" />-->
        <!--</el-form-item>-->
        <el-form-item label="商品名称" prop="goodsName">

          <el-input disabled v-model="form.goodsName" placeholder="请输入商品名称"/>

        </el-form-item>

        <el-form-item label="标题" prop="title">

          <el-input  disabled v-model="form.title" placeholder="请输入标题" />

        </el-form-item>

        <el-form-item label="审核失败原因" prop="reason">
          <el-input type="textarea"  v-model="form.reason" placeholder="请输入审核失败原因" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-bottom: 30px">
        <el-button type="primary" style="float: left;" @click="submitForm">审核成功</el-button>
        <el-button style="float: right;"  @click="submitForm1">审核失败</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="open1" width="550px">
      <el-table
        :data=" PariseList"
        style="width: 100%">
        <el-table-column
          prop="userName"
          label="用户名"
          width="250">
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="点赞时间"
          width="250">
        </el-table-column>

      </el-table>
      <pagination
        v-show="total2>0"
        :total="total2"
        :page.sync="PariseList.pageNum"
        :limit.sync="PariseList.pageSize"
        @pagination="handpraises"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="open2" width="550px">
      <el-table
        :data=" PariseList"
        style="width: 100%">
        <el-table-column
          prop="userName"
          label="用户名"
         >
        </el-table-column>
        <el-table-column
          prop="evaluate"
          label="评论内容"
       >
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="评论时间"
      >
        </el-table-column>
l
      </el-table>
      <pagination
        v-show="total1>0"
        :total="total1"
        :page.sync=" PariseList.pageNum"
        :limit.sync=" PariseList.pageSize"
        @pagination="handcomments"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { listGoods, look, look1, getGoods, delGoods, addGoods, updateGoods, exportGoods } from "@/api/system/goods";

export default {
  name: "Goods",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      PariseList:[],
      itemOptions:[],
      ids: [],
      //数据字典
      statusOptions:[],
      Options:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 二手物品表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      total1: 0,
      total2: 0,
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mobileUserId: undefined,
        goodsName: undefined,
        title: undefined,
        lat: undefined,
        lng: undefined,
        detail: undefined,
        money: undefined,
        momentType: undefined,
        videoUrl: undefined,
        address: undefined,
        reason: undefined,
        examineStatus: undefined,
        pageviews: undefined,
        praises: undefined,
        comments: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_instantaneous_type").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_audit_status").then(response => {
      this.Options = response.data;
    });
    this.getDicts("sys_item_status").then(response => {
      this.itemOptions= response.data;
    });
  },
  methods: {
    /** 查询二手物品列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handcomments(row){

      this.queryParams.goodsId= row.goodsId || this.ids;
      look1(this.queryParams).then(response => {
        console.log(response.rows)
        this.PariseList = response.rows
        this.open2 = true;
        this.total1 = response.total;
        this.title = "查看评论";

      });

    },
    handpraises(row){

      this.queryParams.goodsId= row.goodsId || this.ids;
      look(this.queryParams).then(response => {
        console.log(response.rows)
        this.PariseList = response.rows
        this.total2 = response.total;
        this.open1 = true;
        this.title = "查看点赞";
      });

    },
    Format(row, column) {
      return this.selectDictLabel(this.statusOptions , row.momentType);
    },
    statusFormat(row, column) {
      return this.selectDictLabel(this.Options , row.examineStatus);
    },
    statusFormat1(row, column) {
      return this.selectDictLabel(this.itemOptions ,row.itemStatus);
    },
    // 取消按钮
    cancel() {
        this.open = false;
        this.open1=  false,
        this.open2=  false,
        this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        goodsId: undefined,
        mobileUserId: undefined,
        goodsName: undefined,
        title: undefined,
        lat: undefined,
        lng: undefined,
        detail: undefined,
        money: undefined,
        momentType: undefined,
        videoUrl: undefined,
        address: undefined,
        reason: undefined,
        examineStatus: "0",
        pageviews: undefined,
        praises: undefined,
        comments: undefined,
        remark: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {

      this.resetForm("queryForm");
      this.handleQuery();

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.goodsId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加二手物品";
    },
    /** 审核 */
    handleUpdate(row) {
      this.reset();
      const goodsId = row.goodsId || this.ids
      getGoods(goodsId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "审核";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.form.examineStatus = 1;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.goodsId != undefined) {
            updateGoods(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addGoods(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    submitForm1: function() {
      this.form.examineStatus = 2;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.goodsId != undefined) {
            updateGoods(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addGoods(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const goodsIds = row.goodsId || this.ids;
      this.$confirm('是否确认删除二手物品编号为"' + goodsIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delGoods(goodsIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有二手物品数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportGoods(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
